<template>
   
    <div>
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <div class="banner">
      <van-swipe
        :autoplay="3000"
        indicator-color="#fff"
        width="20px"
        height="20px"
      >
        <van-swipe-item v-for="(item, index) in recommendBanner" :key="index">
          <img v-lazy="item.model.cover" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="recommend-list">
      <ul class="list">
        <li @click=goHotClass>
          <div>
            <a href="javascript:;">
              <img
                src="https://oss-xpc0.xpccdn.com/Upload/edu/2019/01/145c3c3871bd708.png"
                alt=""
              />
              <span>分类热门</span>
            </a>
          </div>
        </li>
        <li @click="goHotRecommend">
          <div>
            <a href="javascript:;">
              <img
                src="https://oss-xpc0.xpccdn.com/Upload/edu/2019/02/015c53c03cb6605.png"
                alt=""
              />
              <span>编辑推荐</span>
            </a>
          </div>
        </li>
        <li  @click="goHotSelect">
          <div>
            <a href="javascript:;">
              <img
                src="https://oss-xpc0.xpccdn.com/Upload/edu/2019/08/055d47e2511d1d8.png"
                alt=""
              />
              <span>场库精选</span>
            </a>
          </div>
        </li>
      </ul>
    </div>
    <div class="list-card">
      <ul class="list">
        <li v-for="(item, i) in list" :key="i" @click="toVideo(item.children[0].model.resource.id)">
          <div class="top">
            <div class="top-left">
              <img v-lazy="item.children[0].model.resource?.author?.userinfo.avatar" alt="" />
              <span>{{ item.children[0].model.resource?.author?.userinfo.username }}</span>
              <img
              src="https://oss-xpc0.xpccdn.com/Upload/edu/2019/09/055d70f8a79a45b.png"
              alt=""
              class="vip"
              v-show="item.children[0].model.resource?.author?.userinfo.vip_flag === 1"
            />
            </div>
            <div class="top-right">
              <div class="action">+ 关注</div>
              <van-icon name="ellipsis" />
            </div>
          </div>
          <div class="center">
            <h5>{{item.children[0].model.resource?.title}}</h5>
            <div class="img-box">
              <img v-lazy=item.children[0].model.resource?.cover alt="" />
            </div>
          </div>
          <div class="bottom">
            <div class="bottom-left">
              <van-icon name="like-o" size="16"   color="#000"/>
              <span>{{ item.children[0].model.resource?.count.count_like }}</span>
              <van-icon name="comment-o" size="16" color="#000" />
              <span>{{ item.children[0].model.resource?.count.count_comment }}</span>
              <van-icon name="star-o" size="16" color="#000" />
              <span>{{ item.children[0].model.resource?.count.count_collect }}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>
</van-pull-refresh>
<router-view></router-view>
    </div>
</template>
<script>
import axios from "axios";
import VueAxios from "vue-axios";
import Vue from 'vue';
import { Toast } from 'vant';
Vue.use(Toast);
export default {
  name: "HomeView",
  data() {
    return {
      list: [],
      isLoading: false,
      recommendBanner: [
    
      ],
      arr: [],
      page:3,
    };
  },
  methods:{
    getRecommended(page){
      axios({
        url:"https://apis.netstart.cn/xpc/home/hot",
        method:"get",
       params:{
         page,
       } 
      }).then((res) => {
        if (res.status == 200) {
          this.recommendBanner = res.data.data.children[0].children;
          this.list = res.data.data.children;
          this.list = this.list.slice(2);
          this.isLoading = false
        }
      });
    },
    toVideo(id){
      this.$router.push({
        path: "/Video",
        query: {id: id},
      });
    },
    onRefresh() {
      setTimeout(() => {
        this.getRecommended();
        this.isLoading = false;
      }, 1000);
    },
    goHotClass(){
        this.$router.push({
          path: "/hotclass",
        });
    },
    goHotSelect(){
        this.$router.push({
          path: "/hotselect",
        });
    },
    goHotRecommend(){
        this.$router.push({
          path: "/hotrecommend",
        });
    }
    
  },
  mounted() {
    this.getRecommended(this.page)
  },
 
};

</script>
<style lang="scss" scoped>

.list-card {
  padding-bottom: 60px;
  .list {
    padding: 2.6232vw;
    padding-top: 0;
    background: #f4f4f4;
    li {
      background: #fff;
      border-radius: 15px;
      margin-bottom: 20px;
    }

    .top {
      display: flex;
      justify-content: space-between;
      padding: 2.4155vw 2.4144vw 1vw 2.4vw;
      align-items: center;
      .top-left {
        display: flex;
        align-items: center;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
          margin-right: 5px;
          margin-left: 8px;
        }
        span {
          margin-left: 10px;
        }
      }
      .top-right {
        display: flex;
        align-items: center;
        div {
          color: #d65644;
        }
        .van-icon {
          transform: rotate(90deg);
          margin-left: 25px;
        }
      }
    }
    .center {
      h5 {
        margin-top: 10px;
        margin-bottom: 10px;
        padding: 0 2.4155vw;
        margin-left: 25px;
      }
      .img-box {
        img {
          width: 100%;
          height: 340px;
        }
      }
    }
    .bottom {
      width: 100%;
      padding: 15px 0;
      .bottom-left {
        text-align: center;
        display: flex;
        justify-content: space-between;
        align-items: center;
        line-height: 20px;
        .van-icon {
          left: 9.333vw;
        }
        span {
          margin-left: 10px;
          flex-grow: 1;
        }
      }
    }
  }
}
.recommend-list {
  width: 94.686vw;
  margin-left: 10px;
  margin-top: 4.1063vw;
  .list {
    display: flex;
    justify-content: space-around;
    li {
      position: relative;
      div {
        width: 18.1159vw;
        height: 21.256vw;
        box-sizing: border-box;
        padding: 20px;
        justify-content: center;
        align-items: center;
        a {
          display: flex;
          flex-direction: column;
          img {
            width: 7.971vw;
            height: 7.971vw;
            padding: 0 2.5401vw;
          }
          span {
            margin-top: 2.657vw;
            text-align: center;
          }
        }
      }
    }
  }
}
.title-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2.4155vw;
  width: 94.4444vw;
  h2 {
    margin-left: 2.4155vw;
  }
  span {
    color: #e4393c;
  }
}
.nav-list {
  width: 94.4444vw;
  margin-left: 2.4155vw;
  margin-top: 3.8309vw;
  padding-bottom: 60px;
  .nav-list-bar {
    
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    li {
      margin-bottom: 2.4155vw;
      border-radius: 20px;
      overflow: hidden;
      position: relative;
    }
    img {
      width: 45.1691vw;
      height: 31.8841vw;
    }
    span {
      position: absolute;
      top: 2.4155vw;
      left: 2.4155vw;
      font-size: 3.9444vw;
    }
  }
}
</style>
<style lang="scss">
.banner {
  width: 94.686vw;
  height: 51vw;
  border-radius: 20px;
  margin-left: 10px;
  overflow: hidden;
  margin-bottom: 20px;
  img {
    width: 94.686vw;
    height: 51vw;
    // border-radius: 20px;
  }
  .van-swipe__indicator {
    width: 14px;
    height: 14px;
  }
}
</style>